package org.light.generator;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.light.core.Writeable;
import org.light.domain.Domain;
import org.light.domain.Statement;
import org.light.domain.StatementList;
import org.light.exception.ValidateException;
import org.light.utils.WriteableUtil;

public class JsonImageValueProcessorGenerator extends Generator{	
	private static final long serialVersionUID = -4790994605747142428L;
	protected Domain sampleDomain;
	
	public Domain getSampleDomain() {
		return sampleDomain;
	}


	public void setSampleDomain(Domain sampleDomain) {
		this.sampleDomain = sampleDomain;
	}

	public JsonImageValueProcessorGenerator(){
		super();		
		this.standardName = "JsonImageValueProcessorGenerator";
		this.fileName = "JsonImageValueProcessor.java";
	}	
	
	@Override
	public StatementList generateStatementList() throws ValidateException {
    	List<Writeable> sList = new ArrayList<Writeable>();
        sList.add(new Statement(1000L,0,"package "+this.sampleDomain.getPackageToken()+".utils;"));
        sList.add(new Statement(2000L,0,""));
        sList.add(new Statement(3000L,0,"import java.text.SimpleDateFormat;"));
        sList.add(new Statement(4000L,0,"import java.util.Date;"));
        sList.add(new Statement(5000L,0,"import java.util.Locale;"));
        sList.add(new Statement(6000L,0,""));
        sList.add(new Statement(7000L,0,"import net.sf.json.JsonConfig;"));
        sList.add(new Statement(8000L,0,"import net.sf.json.processors.JsonValueProcessor;"));
        sList.add(new Statement(9000L,0,"/**"));
        sList.add(new Statement(10000L,0,"* @author Jerry shen"));
        sList.add(new Statement(11000L,0,"*"));
        sList.add(new Statement(12000L,0,"*/"));
        sList.add(new Statement(13000L,0,"public class JsonImageValueProcessor implements JsonValueProcessor {"));
        sList.add(new Statement(14000L,1,"public Object processArrayValue(Object value, JsonConfig config) {"));
        sList.add(new Statement(15000L,2,"return process(value);"));
        sList.add(new Statement(16000L,1,"}"));
        sList.add(new Statement(17000L,0,""));
        sList.add(new Statement(18000L,1,"public Object processObjectValue(String key, Object value, JsonConfig config) {"));
        sList.add(new Statement(19000L,2,"if (StringUtil.isBlank(value)) return \"\";"));
        sList.add(new Statement(20000L,2,"return process(value);"));
        sList.add(new Statement(21000L,1,"}"));
        sList.add(new Statement(22000L,1,""));
        sList.add(new Statement(23000L,1,"private Object process(Object value){"));
        sList.add(new Statement(24000L,2,"if (StringUtil.isBlank(value)) return \"\";"));
        sList.add(new Statement(25000L,2,"byte [] iValue = (byte []) value;"));
        sList.add(new Statement(25500L,2,"if (iValue.length < 20) return \"\";"));
        sList.add(new Statement(26000L,2,"String result = ImageUtil.getImageStr(iValue);"));
        sList.add(new Statement(27000L,2,"if (StringUtil.isBlank(result)) return \"\";"));
        sList.add(new Statement(28000L,2,"else return result;"));
        sList.add(new Statement(29000L,1,"}"));
        sList.add(new Statement(30000L,0,"}"));
              
    	return WriteableUtil.merge(sList);
	}
}
